//
// Created by lingzhitech on 25-10-9.
//

#ifndef EXERCISE1308_HPP
#define EXERCISE1308_HPP
#include <string>

class HasPtr
{
public:
    HasPtr(const std::string &s = std::string()) : ps(new std::string(s)), i(0) {}
    HasPtr(const HasPtr& hp) :ps(new std::string(*hp.ps)), i(hp.i) {}
    HasPtr& operator=(const HasPtr& hp) {
        if (this != &hp) {
            auto newp = new std::string(*hp.ps); // 复制右侧对象的字符串
            delete ps;                           // 释放旧内存
            ps = newp;                           // 指向新内存
            i = hp.i;                            // 拷贝整数
        }
        return *this;
    }
    ~HasPtr() {
        delete ps;
    }
private:
    std::string *ps;
    int i;
};
#endif //EXERCISE1308_HPP
